<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>学生信息管理系统 - 主页</title>
    <style>
        .container {
            width: 90%;
            margin: 20px auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            border-radius: 5px;
        }
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            background-color: #fff;
        }
        th, td {
            padding: 12px 8px;
            border: 1px solid #ddd;
            text-align: center;
        }
        th {
            background-color: #f5f5f5;
            font-weight: bold;
        }
        tr:nth-child(even) {
            background-color: #fafafa;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        .actions {
            display: flex;
            gap: 10px;
            justify-content: center;
        }
        .actions a {
            text-decoration: none;
            padding: 5px 10px;
            border-radius: 3px;
            font-size: 14px;
        }
        .edit {
            background-color: #4CAF50;
            color: white;
        }
        .delete {
            background-color: #f44336;
            color: white;
        }
        .add-btn {
            background-color: #2196F3;
            color: white;
            padding: 10px 20px;
            text-decoration: none;
            border-radius: 5px;
            display: inline-block;
            margin-bottom: 20px;
        }
        .welcome {
            font-size: 16px;
            color: #666;
        }
        .logout-btn {
            background-color: #666;
            color: white;
            padding: 8px 15px;
            text-decoration: none;
            border-radius: 4px;
        }
        .score {
            font-weight: bold;
        }
        .good-score {
            color: #4CAF50;
        }
        .bad-score {
            color: #f44336;
        }
        .search-container {
            margin-bottom: 20px;
        }
        .search-form {
            display: flex;
            justify-content: flex-start;
            align-items: center;
        }
        .search-group {
            display: flex;
            gap: 10px;
        }
        .search-group input {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            width: 200px;
        }
        .search-btn {
            padding: 8px 15px;
            background-color: #2196F3;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .reset-btn {
            padding: 8px 15px;
            background-color: #757575;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .search-btn:hover {
            background-color: #1976D2;
        }
        .reset-btn:hover {
            background-color: #616161;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h2>学生成绩管理系统</h2>
            <div>
                <span class="welcome">欢迎，${sessionScope.username}</span>
                <a href="logout" class="logout-btn">退出登录</a>
            </div>
        </div>
        
        <div class="search-container">
            <form action="student" method="get" class="search-form">
                <input type="hidden" name="action" value="search">
                <div class="search-group">
                    <input type="text" name="searchId" placeholder="请输入学号..." 
                           value="${param.searchId}">
                    <button type="submit" class="search-btn">查询</button>
                    <button type="button" onclick="window.location.href='student?action=list'" 
                            class="reset-btn">重置</button>
                </div>
            </form>
        </div>
        
        <a href="add-student.jsp" class="add-btn">添加学生</a>
        
        <table>
            <tr>
                <th>学号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>班级</th>
                <th>数据库</th>
                <th>linux操作系统</th>
                <th>Java程序设计</th>
                <th>平均分</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${students}" var="student">
                <tr>
                    <td>${student.studentId}</td>
                    <td>${student.name}</td>
                    <td>${student.gender}</td>
                    <td>${student.className}</td>
                    <td class="score ${student.scores['数据库'] >= 60 ? 'good-score' : 'bad-score'}">
                        <fmt:formatNumber value="${student.scores['数据库']}" pattern="0.0"/>
                    </td>
                    <td class="score ${student.scores['操作系统'] >= 60 ? 'good-score' : 'bad-score'}">
                        <fmt:formatNumber value="${student.scores['操作系统']}" pattern="0.0"/>
                    </td>
                    <td class="score ${student.scores['Java程序设计'] >= 60 ? 'good-score' : 'bad-score'}">
                        <fmt:formatNumber value="${student.scores['Java程序设计']}" pattern="0.0"/>
                    </td>
                    <td class="score ${student.average >= 60 ? 'good-score' : 'bad-score'}">
                        <fmt:formatNumber value="${student.average}" pattern="0.0"/>
                    </td>
                    <td class="actions">
                        <a href="student?action=edit&id=${student.studentId}" class="edit">编辑</a>
                        <a href="student?action=delete&id=${student.studentId}" 
                           onclick="return confirm('确定要删除吗？')" class="delete">删除</a>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </div>
</body>
</html>